<?php

namespace App\Http\Models\Permissions;

use Illuminate\Foundation\Http\FormRequest;

/*
 * PermissionsFrom  权限表单验证
 *
 * rules() 权限验证规则
 * messages() 权限验证提示信息
 *
 * @author 金飞虎
 * @email 870741306@qq.com
 * @date 2018/4/5
 * */

class PermissionsFrom extends FormRequest
{
    public function authorize()
    {
        return true;
    }

    public function rules()
    {
        //注意表名如果有s的话尽量去掉
        $id = $this->route("permission");
        if ($id) {
            $id = decryptUrl($id);
        }
        return [
            'permissions_name' => 'required|max:30|unique:permissions,permissions_name,' . $id,
            'urls' => 'required|max:30',
        ];
    }

    public function messages()
    {
        return [
            'permissions_name.required' => "权限名称不能为空",
            'permissions_name.max' => "权限名称不能超过30个字符",
            'permissions_name.unique' => '权限名称已存在',
            'urls.required' => '权限说明不能为空',
            'urls.max' => "权限说明不能超过30个字符",
            'urls.unique' => "权限名称已存在"
        ];
    }
}
